<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #form {
      max-width: 300px;
      margin: 0 auto;
      padding: 20px;
      border: 1px solid #ccc;
      border-radius: 5px;
      text-align: center;
    }

    h2 {
      margin-bottom: 20px;
    }

    input {
      width: 100%;
      padding: 10px;
      margin-bottom: 10px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }

    button {
      width: 100%;
      padding: 10px;
      background-color: #007bff;
      color: #fff;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    }

    button:hover {
      background-color: #0056b3;
    }
  </style>
</head>

<body>
  <form id="form" action="/register" method='POST'>
    <h2>用户注册</h2>
    <input type="text" id="username" name="username" placeholder="用户名">
    <input type="password" id="password" name="password" placeholder="密码">
    <button type="submit">注册</button>
  </form>
  <script>
    alert('用户名至少一个字母开头,后面跟5到16个字母数字或下划线 密码至少包含一个数字、一个大写字母和一个小写字母长度至少为8个字符')
    document.getElementById('form').addEventListener('submit', function (event) {

      var username = document.getElementById('username').value;
      var password = document.getElementById('password').value;
      if (username === "" || password === "") {
        event.preventDefault();
        alert('用户名或密码不能为空')
        return;
      }

      var usernameReg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
      var passwordReg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/;
      if (!usernameReg.test(username) && !passwordReg.test(password)) {
        alert('用户名或密码格式不正确')
        event.preventDefault();

      } else {
        alert('注册成功')
      }
    })





  </script>
</body>

</html>